package com.zhoug.libapp;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

import com.zhoug.libapp.test.SignViewActivity;
import com.zhoug.libapp.test.TestAutoScrollListActivity;
import com.zhoug.libapp.test.TestBaseRecyclerViewAdapterActivity;
import com.zhoug.libapp.test.TestPullToRefreshViewActivity;
import com.zhoug.libapp.test.TestStickyScrollViewActivity;
import com.zhoug.permission.PermissionUtil;
import com.zhoug.widget.activities.BaseActivity;
import com.zhoug.widget.customview.IndicatorView;
import com.zhoug.widget.customview.RatingBar;
import com.zhoug.widget.customview.date.DateChooser;
import com.zhoug.widget.customview.dialog.ButtonDialog;
import com.zhoug.widget.customview.dialog.EditDialogFragment;
import com.zhoug.widget.customview.dialog.ListDialog;
import com.zhoug.widget.customview.dialog.ProgressDialog;
import com.zhoug.widget.customview.gender.GenderChooser;
import com.zhoug.widget.divider.DividerItemWithoutLastItem;
import com.zhoug.widget.util.ActivityUtil;
import com.zhoug.widget.util.AppUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {
    private static final String TAG = "MainActivity";
    @BindView(R.id.indicatorView)
    IndicatorView indicatorView;
    @BindView(R.id.ratingBar)
    RatingBar ratingBar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private RecyclerView mRecyclerView;
    private List<String> mData = new ArrayList<>();
    private Adapter mAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        init();

      /*  IndicatorView indicatorView=findViewById(R.id.indicatorView);
        indicatorView.setCount(5);
        indicatorView.setDistance(10);
        indicatorView.setRadius(20);
        indicatorView.setColorSelected(Color.RED);
        indicatorView.setColorNormal(Color.BLUE);
        indicatorView.setSelection(3);*/

    }

    private void initData() {
        mData.clear();
        mData.add("0,EditDialogFragment");
        mData.add("1,测试MFileProvider");
        mData.add("2,测试PermissionUtil");
        mData.add("3,测试SignView 签名");
        mData.add("4,测试日期选择");
        mData.add("5,测试性别选择选择");
        mData.add("6,测试ButtonDialog");
        mData.add("7,测试ListDialog");
        mData.add("8,测试ProgressDialog");
        mData.add("9,测试BaseRecyclerViewAdapter");
        mData.add("10,测试AutoScrollListView跑马灯");
        mData.add("11,测试StickyScrollView粘性ScrollView");
        mData.add("11,测试PullToRefreshLayout");

    }

    private View.OnClickListener listener = v -> {
        int pos = (int) v.getTag();
        switch (pos) {
            case 0:
                EditDialogFragment editDialogFragment = new EditDialogFragment();
                editDialogFragment.setConfirmOnclickListener(value -> {
                    Toast.makeText(this, "值:" + "value", Toast.LENGTH_SHORT).show();
                });
                Log.d(TAG, EditDialogFragment.class.getName());
                editDialogFragment.show(getSupportFragmentManager(), EditDialogFragment.class.getName());
                break;
            case 1:
                AppUtil.getFileProvideIntent(this, "", "image/*");


                break;
            case 2:
                new PermissionUtil()
                        .setContext(this)
                        .addPermissions(PermissionUtil.CAMERA,
                                PermissionUtil.LOCATION,
                                PermissionUtil.PHONE,
                                PermissionUtil.STORAGE)
                        .setNotAsking("需要权限")
                        .setShowNotAskingDialig(true)
                        .setCallback(success -> {
                            Toast.makeText(this, "" + success, Toast.LENGTH_SHORT).show();
                        })
                        .request();


                break;
            case 3:
                ActivityUtil.startActivity(this, SignViewActivity.class);

                break;
            case 4:
//                IDateChooser iDateChooser = DateChooserFactory.create(this);
                DateChooser dateChooser = new DateChooser(this);
                dateChooser.setCallback((year, month, day) -> {
                    Toast.makeText(MainActivity.this, "" + year + "-" + month + "-" + day, Toast.LENGTH_SHORT).show();

                });
                dateChooser.setCancelable(true);
                dateChooser.setMaxYear("2020");
                dateChooser.show();

                break;
            case 5:
                GenderChooser genderChooser = new GenderChooser(this);
                genderChooser.setCallback(gender -> Toast.makeText(MainActivity.this, "" + gender, Toast.LENGTH_SHORT).show());
                genderChooser.show();

                break;
            case 6:
                ButtonDialog buttonDialog = new ButtonDialog(this);
                buttonDialog.setOnclickListener1("zxc", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        buttonDialog.cancel();
                        Toast.makeText(MainActivity.this, "zxc", Toast.LENGTH_SHORT).show();
                    }
                });
                buttonDialog.setOnclickListener2("111", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        buttonDialog.cancel();
                        Toast.makeText(MainActivity.this, "111", Toast.LENGTH_SHORT).show();

                    }
                });
                buttonDialog.hideTitle(true);
                buttonDialog.setMessage("zxczxc");
                buttonDialog.setCircle(true);
                buttonDialog.show();
                break;
            case 7:
                ListDialog listDialog = new ListDialog(this, R.style.dialog_full);
                listDialog.addQuxiaoBtn(true)
                        .setData(Arrays.asList("zxc", "zxcas", "zxcs", "asfd"))
                        .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                listDialog.cancel();
                                Toast.makeText(MainActivity.this, listDialog.getData().get(position), Toast.LENGTH_SHORT).show();
                            }
                        })
                        .setDefWindowAnimations()
                        .setTitle("zxczx")
                        .setTextGravity(Gravity.LEFT)
                        .show();

                break;
            case 8:
                ProgressDialog progressDialog = new ProgressDialog(this);
                progressDialog.setZezhao(true);
                progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress1));
//                progressDialog.setTitle("zxc");
                progressDialog.show();

                break;
            case 9:
                ActivityUtil.startActivity(this,TestBaseRecyclerViewAdapterActivity.class );

                break;
            case 10:
                ActivityUtil.startActivity(this,TestAutoScrollListActivity.class );

                break;
            case 11:
                ActivityUtil.startActivity(this,TestStickyScrollViewActivity.class );



                break;
            case 12:
                ActivityUtil.startActivity(this,TestPullToRefreshViewActivity.class );



                break;
            case 13:



                break;
            case 14:



                break;
            case 15:



                break;
        }


    };


    private void init() {
        mRecyclerView = findViewById(R.id.recyclerView);
        initData();
        mAdapter = new Adapter();
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new DividerItemWithoutLastItem(this, OrientationHelper.VERTICAL));
        mRecyclerView.setAdapter(mAdapter);
    }

    private class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {


        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            return new ViewHolder(getLayoutInflater().inflate(R.layout.list_main, parent, false));
        }

        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            holder.textView.setText(mData.get(position));
            holder.itemView.setClickable(true);
            holder.itemView.setTag(position);
            holder.itemView.setOnClickListener(listener);

        }

        @Override
        public int getItemCount() {
            return mData.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder {
            TextView textView;

            ViewHolder(View itemView) {
                super(itemView);
                init(itemView);
            }

            private void init(View itemView) {
                textView = itemView.findViewById(R.id.tv_list_main);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == 102) {
            for (int i = 0; i < permissions.length; i++) {
                Log.d(TAG, ": " + permissions[i]);
                Log.d(TAG, ": " + grantResults[i]);
                Log.d(TAG, ": >>>>>>>>>>>>>>>>>>>>>>>>>");

            }

        }


    }

}
